import json
import sys
import os
import traceback
import pandas as pd
import serial
import time
sys.path.append(os.getcwd())

#读取配置文件
def get_cfg(file_path):
    with open(file_path, 'r') as file:
        config = json.load(file)
    return config

#将excel文件中的AT指令转换为二进制数据,并返回at_tx列表。
def excel_at_tx(path_xls):
        at_tx = []
        try:
            xls_data = pd.DataFrame(pd.read_excel(path_xls))
            for i in range(0,len(xls_data['待测AT指令'])):  #AT指令的测试范围
                at_tx.append(xls_data['待测AT指令'][i])
        except:
            print(traceback.format_exc())
        return at_tx

if __name__ == '__main__':
    '''
    file_path = 'mq_config.json'
    para = get_cfg(file_path)
    print(para,type(para),json.dumps(para),type(json.dumps(para)))  #{'baudrate': 115200, 'timeout': 1} <class 'dict'> <class 'str'>
    '''
    excel_path = './at.xlsx'
    at_tx = excel_at_tx(excel_path)
    print(at_tx,type(at_tx))